package com.jz.community.moduleshoppingguide.home.presenter;

import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.moduleshoppingguide.home.bean.CategoriesGoodsBean;
import com.jz.community.moduleshoppingguide.home.bean.ChunnelTypeBean;
import com.jz.community.moduleshoppingguide.home.model.ShoppingGuideModel;
import com.jz.community.moduleshoppingguide.home.model.ShoppingModelGuideImpl;
import com.jz.community.moduleshoppingguide.home.ui.view.ChannelOutView;

import java.util.List;

/**
 * Created by Tony.Fan on 2018/3/13 10:42
 */
public class ChannelOutPresenter extends BaseLifeCyclePresent<ChannelOutView.View> implements ChannelOutView.Presenter {

    private ShoppingGuideModel shoppingModel;
    private ChannelOutView.View mView;

    public ChannelOutPresenter(ChannelOutView.View v) {
        mView = v;
        shoppingModel = new ShoppingModelGuideImpl(v.getContext());
    }

    @Override
    public void setPresenter(ChannelOutView.View v) {
        super.setPresenter(v);
    }

    @Override
    public void getChunnelCategories(String categoryId, String cityCode) {
        shoppingModel.getChunnelCategories(categoryId, cityCode, new OnLoadListener<List<ChunnelTypeBean>>() {
            @Override
            public void onSuccess(List<ChunnelTypeBean> list) {
                mView.showChannel(list);
            }

            @Override
            public void onFail(String s, int code) {
                mView.showChannelError(s);
            }
        });
    }

    @Override
    public void getOutGoodsInfo(String id, String shopId, String sort, int page, int size) {
        shoppingModel.getChannelOutGoods(id, shopId, sort, page, size, new OnLoadListener<CategoriesGoodsBean>() {
            @Override
            public void onSuccess(CategoriesGoodsBean categoriesGoodsBean) {
                mView.showOutGoodsInfo(categoriesGoodsBean);
            }

            @Override
            public void onFail(String msg, int code) {
                mView.showOutGoodsError(msg);
            }
        });

    }


}
